home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / ExternalWindow.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  28.5 KB  |  883 lines  |  [TEXT/CWIE]

  1. // ExternalWindow.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. import java.awt.Frame;
  10. import java.awt.Insets;
  11. import java.awt.Dimension;
  12. import java.awt.Toolkit;
  13. import java.lang.IllegalMonitorStateException;
  14.  
  15. /** Object subclass providing a platform-dependent window containing IFC
  16.   * components. Like InternalWindow, it implements the
  17.   * Window interface. The following code demonstrates the normal sequence for
  18.   * creating an ExternalWindow:
  19.   * <pre>
  20.   *     window = new ExternalWindow();
  21.   *     windowSize = window.windowSizeForContentSize(contentWidth, contentHeight);
  22.   *     window.sizeTo(windowSize.width, windowSize.height);
  23.   *     window.moveTo(x, y);
  24.   *     window.show();
  25.   * </pre>
  26.   * @note 1.0 application wide document window support added.
  27.   * @note 1.0 changes for Menu support
  28.   * @note 1.0 fixed problem with very fast hide/show patterns
  29.   * @note 1.0 fixed problem with view being resized by showModally()
  30.   * @note 1.0 center will now use the screen size
  31.   * @note 1.0 changes for new Window interface and focus model
  32.   * @note 1.0 added moveToFront/Back
  33.   */
  34. public class ExternalWindow implements Window, ApplicationObserver {
  35.     java.awt.Window             awtWindow;
  36.     private FoundationPanel     panel;
  37.     private WindowOwner         owner;
  38.     private int                 type;
  39.     private Size                minimumSize;
  40.     private String              title;
  41.     private Rect                bounds;
  42.     private boolean             resizable=true;
  43.     private boolean             visible = false;
  44.     private boolean             hideOnPause = true;
  45.     private boolean             showOnResume = false;
  46.     private boolean             containsDocument = false;
  47.     private boolean             waitingForInvalidation = false;
  48.     Menu                        menu;
  49.     MenuView                    menuView;
  50.  
  51.     final static String         AWTWINDOW_KEY = "awtWindow",
  52.                                 PANEL_KEY = "panel",
  53.                                 OWNER_KEY = "owner",
  54.                                 TYPE_KEY = "type",
  55.                                 MINSIZE_KEY = "minimumSize",
  56.                                 MENU_KEY = "menu",
  57.                                 HIDEONPAUSE_KEY = "hideOnPause",
  58.                                 CONTAINS_DOCUMENT_KEY = "containsDocument";
  59.  
  60.  
  61.     /** Constructs an ExternalWindow with a style of Window.TITLE_TYPE.
  62.       */
  63.     public ExternalWindow() {
  64.         this(TITLE_TYPE);
  65.     }
  66.  
  67.     private java.awt.Frame firstRootViewParentFrame() {
  68.        Application app = Application.application();
  69.        RootView firstRootView;
  70.  
  71.        if( app != null ) {
  72.            firstRootView = app.firstRootView();
  73.            if( firstRootView != null ) {
  74.                FoundationPanel panel = firstRootView.panel();
  75.                java.awt.Component parent;
  76.                parent = panel.getParent();
  77.                while(parent != null && !(parent instanceof java.awt.Frame))
  78.                    parent = parent.getParent();
  79.                if( parent != null ) {
  80.                    return (java.awt.Frame) parent;
  81.                }
  82.            }
  83.        }
  84.        return appletParentFrame();
  85.     }
  86.  
  87.     private java.awt.Frame appletParentFrame() {
  88.         java.applet.Applet applet = AWTCompatibility.awtApplet();
  89.         java.awt.Component parent;
  90.  
  91.         if( applet != null ) {
  92.             parent = applet.getParent();
  93.             while(parent != null && !(parent instanceof java.awt.Frame))
  94.                 parent = parent.getParent();
  95.         } else
  96.             return null;
  97.         return (java.awt.Frame) parent;
  98.     }
  99.  
  100.     private synchronized void validateAWTWindow(int type,boolean modal)  {
  101.         if(waitingForInvalidation)
  102.             waitingForInvalidation = false; /* Cancel any pending invalidation */
  103.         if( awtWindow == null ) {
  104.             Application app = Application.application();
  105.             Insets insets;
  106.             RootView rootView = panel.rootView();
  107.             boolean rootViewAutoresize;
  108.  
  109.             if( modal ) {
  110.                 FoundationDialog dialog = createDialog();
  111.                 dialog.setExternalWindow( this );
  112.                 awtWindow = dialog;
  113.             } else {
  114.                 if( type == TITLE_TYPE ) {
  115.                     FoundationFrame netcodeFrame = createFrame();
  116.                     netcodeFrame.setExternalWindow(this);
  117.                     awtWindow = netcodeFrame;
  118.                 } else {
  119.                     FoundationWindow netcodeWindow = createWindow();
  120.                     netcodeWindow.setExternalWindow(this);
  121.                     awtWindow = netcodeWindow;
  122.                 }
  123.             }
  124.  
  125.             /** java.awt.window does not implement setResizable(boolean)
  126.              *  this is why we are testing classes like this.
  127.              */
  128.             if( awtWindow instanceof java.awt.Dialog )
  129.                 ((java.awt.Dialog)awtWindow).setResizable(resizable);
  130.             else if( awtWindow instanceof FoundationFrame)
  131.                 ((FoundationFrame)awtWindow).setResizable(resizable);
  132.  
  133.             awtWindow.addNotify();
  134.             awtWindow.add(panel);
  135. //            rootViewAutoresize = rootView.doesAutoResizeSubviews();
  136. //            rootView.setAutoResizeSubviews(false);
  137.             awtWindow.reshape( bounds.x, bounds.y, bounds.width, bounds.height);
  138.             awtWindow.layout();
  139. //            rootView.setAutoResizeSubviews( rootViewAutoresize);
  140.  
  141.             if (type == TITLE_TYPE) {
  142.                 if( awtWindow instanceof java.awt.Dialog )
  143.                     ((java.awt.Dialog)awtWindow).setTitle(title);
  144.                 else
  145.                     ((FoundationFrame)awtWindow).setTitle(title);
  146.             }
  147.  
  148.             if (menu != null) {
  149.                 ((FoundationFrame)awtWindow).setMenuBar(menu.awtMenuBar());
  150.             }
  151.         }
  152.     }
  153.  
  154.     // This method is only called by the WindowInvalidationAgent
  155.     // to release the real AWT window objects in response to a hide() call.
  156.     synchronized void invalidateAWTWindow() {
  157.         if( waitingForInvalidation ) {
  158.             _invalidateAWTWindow();
  159.         }
  160.         waitingForInvalidation = false;
  161.     }
  162.  
  163.     /// This invalidate method does the real work of releasing the AWT resources.
  164.     void _invalidateAWTWindow() {
  165.         if( awtWindow != null ) {
  166.             bounds = bounds(); /* Sync window location with the ivar */
  167.             awtWindow.remove(panel);
  168.             awtWindow.dispose();
  169.             awtWindow = null;
  170.         }
  171.     }
  172.  
  173.     /** Constructs an ExternalWindow of type <B>windowType</B>.  Creates
  174.       * the platform-dependent (native) window that will hold the
  175.       * ExternalWindow's contents, as well as the window's RootView
  176.       * and AWT Panel.  The ExternalWindow does <I>not</I> appear onscreen
  177.       * until it receives a <b>show()</b> message.
  178.       */
  179.     public ExternalWindow(int windowType) {
  180.         RootView rootView;
  181.         Application app = Application.application();
  182.  
  183.         title = "";
  184.         type = windowType;
  185.         panel = createPanel();
  186.         bounds = new Rect(0,0,0,0);
  187.         setBounds(0, 0, 150, 150); /* Size should not be 0 for inset to work */
  188.         Application.application().addObserver(this);
  189.     }
  190.  
  191.     /** Sets the ExternalWindow's title (the string displayed in its title
  192.       * bar).
  193.       */
  194.     public void setTitle(String aTitle) {
  195.  
  196.         if( aTitle == null )
  197.             aTitle = "";
  198.  
  199.         title = aTitle;
  200.         if( awtWindow != null && type == TITLE_TYPE) {
  201.             if( awtWindow instanceof java.awt.Dialog )
  202.                 ((java.awt.Dialog)awtWindow).setTitle(title);
  203.             else
  204.                 ((FoundationFrame)awtWindow).setTitle(title);
  205.         }
  206.     }
  207.  
  208.     /** Returns the ExternalWindow's title.
  209.       * @see #setTitle
  210.       */
  211.     public String title() {
  212.         return title;
  213.     }
  214.  
  215.     /** Displays the ExternalWindow.
  216.       * @see #hide
  217.       */
  218.     public void show() {
  219.         validateAWTWindow( type, false );
  220.         if (owner == null || owner.windowWillShow(this)) {
  221.             awtWindow.show();
  222.             panel.rootView.setVisible(true);
  223.             visible = true;
  224.             showOnResume = false;
  225.             awtWindow.toFront();
  226.             if (owner != null)
  227.                 owner.windowDidShow(this);
  228.         }
  229.  
  230.     }
  231.  
  232.     /** Displays the ExternalWindow until dismissed by the user.  This method
  233.       * will not return until the user closes the Window.
  234.       */
  235.     public void showModally() {
  236.         Application application = Application.application();
  237.         Event event;
  238.         EventLoop eventLoop = Application.application().eventLoop();
  239.  
  240.         if (type == BLANK_TYPE)
  241.             throw new InconsistencyException(
  242.                                         "Cannot run blank windows modally");
  243.  
  244.         if (owner == null || owner.windowWillShow(this)) {
  245.             validateAWTWindow(type, true );
  246.             ModalDialogManager modalManager;
  247.  
  248.             modalManager = new ModalDialogManager((java.awt.Dialog)awtWindow);
  249.             modalManager.show();
  250.             showOnResume = false;
  251.             panel.rootView.setVisible(true);
  252.             visible = true;
  253.  
  254.             if (owner != null)
  255.                 owner.windowDidShow(this);
  256.  
  257.             application.beginModalSessionForView(this.rootView());
  258.             application.drawAllDirtyViews();
  259.             while (this.isVisible()) {
  260.                 event = eventLoop.getNextEvent();
  261.                 try {
  262.                     eventLoop.processEvent(event);
  263.                 } catch (Exception e) {
  264.                     System.err.println("Uncaught Exception.");
  265.                     e.printStackTrace(System.err);
  266.                     System.err.println("Restarting modal EventLoop.");
  267.                 }
  268.             }
  269.             application.endModalSessionForView(this.rootView());
  270.         }
  271.     }
  272.  
  273.     /** Hides the ExternalWindow.
  274.       * @see #show
  275.       */
  276.     public void hide() {
  277.         WindowInvalidationAgent agent;
  278.  
  279.         if (awtWindow == null) {
  280.             return;
  281.         }
  282.  
  283.         if (owner == null || owner.windowWillHide(this)) {
  284.             if(containsDocument() && isCurrentDocument())
  285.                 Application.application().chooseNextCurrentDocumentWindow(this);
  286.             awtWindow.hide();
  287.             visible = false;
  288.             panel.rootView.setVisible(false);
  289.             showOnResume = false;
  290.             if (owner != null)
  291.                 owner.windowDidHide(this);
  292.             agent = new WindowInvalidationAgent(this);
  293.             waitingForInvalidation = true;
  294.             agent.run();
  295.         }
  296.     }
  297.  
  298.     /** Returns <b>true</b> if the ExternalWindow is currently visible
  299.       * (is onscreen).
  300.       */
  301.     public boolean isVisible() {
  302.         return visible;
  303.     }
  304.  
  305.     /** Closes the ExternalWindow and destroys the native window.
  306.       */
  307.     public void dispose() {
  308.         RootView rootView = rootView();
  309.         Application app = rootView.application();
  310.  
  311.         if (containsDocument() && isCurrentDocument()) {
  312.             app.chooseNextCurrentDocumentWindow(this);
  313.         }
  314.  
  315.         visible = false;
  316.         /** Should invalidate before removing the root view
  317.           * invalidate might cause an awt layout and a post event
  318.           */
  319.         _invalidateAWTWindow();
  320.         app.removeObserver(this);
  321.         app.removeRootView(rootView);
  322.         panel.rootView.setVisible(false);
  323.         panel.rootView = null;
  324.     }
  325.  
  326.     /** Sets the ExternalWindow's Menu. This is rendered as a native
  327.       * menu that is created through the AWT Menu API.
  328.       * @see Menu, #setMenuView
  329.       *
  330.       */
  331.     public void setMenu(Menu aMenu) {
  332.         java.awt.MenuBar menuBar;
  333.  
  334.         menu = aMenu;
  335.         if (!menu.isTopLevel()) {
  336.             throw new InconsistencyException("menu must be main menu");
  337.         }
  338.  
  339.         menu.setApplication(rootView().application());
  340.  
  341.         menuBar = menu.awtMenuBar();
  342.         if (awtWindow != null) {
  343.             ((FoundationFrame) awtWindow).setMenuBar(menuBar);
  344.         }
  345.     }
  346.  
  347.     /** Returns the ExternalWindow's Menu.
  348.       * @see #setMenu
  349.       */
  350.     public Menu menu() {
  351.         return menu;
  352.     }
  353.  
  354.     /** Sets the MenuView that will appear along the top edge of the Window.
  355.       * This will be an IFC View-based Menu.
  356.       * @see MenuView, #setMenu
  357.       *
  358.       */
  359.     public void setMenuView(MenuView aMenuView) {
  360.         int x, y, width, height;
  361.  
  362.         if (aMenuView != null && aMenuView == menuView) {
  363.             return;
  364.         }
  365.  
  366.         if (menuView != null) {
  367.             menuView.removeFromSuperview();
  368.         }
  369.         menuView = aMenuView;
  370.  
  371.         x = rootView().bounds.x;
  372.         y = rootView().bounds.y;
  373.         width = rootView().bounds.width;
  374.         height = menuView.height();
  375.         menuView.setBounds(x, y, width, height);
  376.  
  377.         addSubview(menuView);
  378.     }
  379.  
  380.     /** Returns the MenuView that appears along the top edge of the Window.
  381.       * @see #setMenuView
  382.       */
  383.     public MenuView menuView() {
  384.         return menuView;
  385.     }
  386.  
  387.     /** Returns the RootView that occupies the ExternalWindow.
  388.       */
  389.     public RootView rootView() {
  390.         return panel.rootView;
  391.     }
  392.  
  393.     /** Returns the Application to which the ExternalWindow belongs.
  394.       */
  395.     Application application() {
  396.         return Application.application();
  397.     }
  398.  
  399.     /** Sets the ExternalWindow's owner, the object interested in learning
  400.       * about special events such as the user closing the ExternalWindow.
  401.       */
  402.     public void setOwner(WindowOwner wOwner) {
  403.         owner = wOwner;
  404.     }
  405.  
  406.     /** Returns the ExternalWindow's owner.
  407.       * @see #setOwner
  408.       */
  409.     public WindowOwner owner() {
  410.         return owner;
  411.     }
  412.  
  413.     void didBecomeMain() {
  414.         if (owner != null)
  415.             owner.windowDidBecomeMain(this);
  416.         if(containsDocument())
  417.             Application.application().makeCurrentDocumentWindow(this);
  418.     }
  419.  
  420.     void didResignMain() {
  421.         if (owner != null)
  422.             owner.windowDidResignMain(this);
  423.     }
  424.  
  425.     /** Returns the Size defining the ExternalWindow's content area. Use this
  426.       * Size to properly position and size any View that you plan to add to the
  427.       * ExternalWindow.
  428.       */
  429.     public Size contentSize() {
  430.         RootView rootView = rootView();
  431.  
  432.         if (rootView == null) {
  433.             return null;
  434.         }
  435.  
  436.         return new Size(rootView.bounds.width, rootView.bounds.height);
  437.     }
  438.  
  439.     /** Adds <b>aView</b> to the ExternalWindow.
  440.       */
  441.     public void addSubview(View aView) {
  442.         RootView rootView = rootView();
  443.         if (rootView != null)
  444.             rootView.addSubview(aView);
  445.     }
  446.  
  447.     /** Sets the Window's bounds to the rectangle (<b>x</b>, <b>y</b>,
  448.       * <b>width</b>, <b>height</b>).  This is the primitive method for
  449.       * resizing or moving.  All the other related methods ultimately call
  450.       * this one.
  451.       */
  452.     public void setBounds(int x, int y, int width, int height) {
  453.         boolean sizeChanged = false;
  454.         Size    deltaSize;
  455.         java.awt.Rectangle wBounds;
  456.  
  457.         if (owner != null &&
  458.             (bounds.width != width || bounds.height != height)) {
  459.             deltaSize = new Size(width - bounds.width, height - bounds.height);
  460.             owner.windowWillSizeBy(this, deltaSize);
  461.             width = bounds.width + deltaSize.width;
  462.             height = bounds.height + deltaSize.height;
  463.         }
  464.  
  465.         if (bounds.x != x || bounds.y != y || bounds.width != width ||
  466.             bounds.height != height) {
  467.             if( bounds.width != width || bounds.height != height )
  468.                 sizeChanged = true;
  469.             bounds.setBounds(x, y, width, height);
  470.             if (awtWindow != null) {
  471.                 awtWindow.reshape(x, y, width, height);
  472.                 wBounds = awtWindow.bounds();
  473.                 bounds.setBounds(wBounds.x, wBounds.y, wBounds.width,
  474.                                  wBounds.height);
  475.                 awtWindow.layout();
  476.  
  477.             }
  478.         }
  479.  
  480.         if( sizeChanged && awtWindow == null ) {
  481.             validateAWTWindow(type,false);
  482.             _invalidateAWTWindow();
  483.         }
  484.     }
  485.  
  486.     /** This method is called by RootView when the it is processing
  487.      *  ResizeEvent to allow the window to update its bounds and to
  488.      *  call windowWillSizeBy
  489.      */
  490.     void validateBounds() {
  491.         if( awtWindow != null ) {
  492.             Rect newBounds;
  493.             java.awt.Point location = awtWindow.location();
  494.             java.awt.Dimension size = awtWindow.size();
  495.             Size deltaSize;
  496.  
  497.             newBounds = new Rect(location.x, location.y, size.width,
  498.                                  size.height);
  499.             if(!newBounds.equals(bounds)) {
  500.                 deltaSize = new Size(newBounds.width - bounds.width,
  501.                                      newBounds.height - bounds.height);
  502.                 if( owner != null )
  503.                     owner.windowWillSizeBy(this,deltaSize);
  504.                 bounds.setBounds(newBounds.x,newBounds.y,
  505.                                  newBounds.width,newBounds.height);
  506.             }
  507.         }
  508.     }
  509.  
  510.     /** Sets the ExternalWindow's bounds to <b>newBounds</b>.
  511.       */
  512.     public void setBounds(Rect newBounds) {
  513.         setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
  514.     }
  515.  
  516.     /** Sets the ExternalWindow's size to (<b>width</b>, <b>height</b>).
  517.       */
  518.     public void sizeTo(int width, int height) {
  519.         setBounds(bounds.x, bounds.y, width, height);
  520.     }
  521.  
  522.     /** Changes the ExternalWindow's size by <b>deltaWidth</b> and
  523.       * <b>deltaHeight</b>.
  524.       */
  525.     public void sizeBy(int deltaWidth, int deltaHeight) {
  526.         setBounds(bounds.x, bounds.y, bounds.width + deltaWidth,
  527.                   bounds.height + deltaHeight);
  528.     }
  529.  
  530.     /** Changes the ExternalWindow's location by <b>deltaX</b> and
  531.       * <b>deltaY</b>.
  532.       */
  533.     public void moveBy(int deltaX, int deltaY) {
  534.         setBounds(bounds.x + deltaX, bounds.y + deltaY, bounds.width,
  535.                   bounds.height);
  536.     }
  537.  
  538.     /** Centers the ExternalWindow (as well as possible for a native window).
  539.       */
  540.     public void center() {
  541.         java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  542.         Rect b = new Rect(this.bounds());
  543.  
  544.         b.x = (int)Math.floor((double)(screenSize.width - b.width) / 2.0);
  545.         b.y = (int)Math.floor((double)(screenSize.height - b.height) / 2.0);
  546.  
  547.         this.setBounds(b);
  548.     }
  549.  
  550.     /** Sets the ExternalWindow's origin to (<b>x</b>, <b>y</b>). */
  551.     public void moveTo(int x, int y) {
  552.         setBounds(x, y, bounds.width, bounds.height);
  553.     }
  554.  
  555.     /** Returns the size the ExternalWindow must be to support a content
  556.       * size of (<B>width</B>, <B>height</B>).
  557.       */
  558.     public Size windowSizeForContentSize(int width, int height) {
  559.         Insets insets;
  560.         boolean hasAWTWindow = (awtWindow != null);
  561.  
  562.         if(!hasAWTWindow)
  563.             validateAWTWindow(type,false);
  564.         insets = awtWindow.insets();
  565.  
  566.         if(!hasAWTWindow)
  567.             _invalidateAWTWindow();
  568.  
  569.         return new Size(width + insets.left + insets.right,
  570.                         height + insets.top + insets.bottom);
  571.     }
  572.  
  573.     /** Returns the View containing the point (<B>x</B>, <B>y</B>).
  574.       */
  575.     public View viewForMouse(int x, int y) {
  576.         return rootView().viewForMouse(x, y);
  577.     }
  578.  
  579.     /** Sets a minimum size for the ExternalWindow.<p>
  580.       * <i><b>Note:</b> The AWT does not appear to support this feature.</i>
  581.       */
  582.     public void setMinSize(int width, int height) {
  583.         minimumSize = new Size(width, height);
  584.     }
  585.  
  586.     /** Returns the ExternalWindow's minimum size, if set. Otherwise,
  587.       * returns <b>null</b>.
  588.       */
  589.     public Size minSize() {
  590.         return minimumSize;
  591.     }
  592.  
  593.    /** Returns a newly-allocated copy of the ExternalWindow's bounding
  594.      * rectangle, which defines the ExternalWindow's size and position.
  595.      */
  596.     public Rect bounds() {
  597.         if( awtWindow != null ) {
  598.             java.awt.Point location = awtWindow.location();
  599.             java.awt.Dimension size = awtWindow.size();
  600.  
  601.             return new Rect(location.x, location.y, size.width, size.height);
  602.         } else
  603.             return new Rect(bounds);
  604.     }
  605.  
  606.     /** Sets whether the ExternalWindow can be resized by the user.
  607.       * Throws an error if called when the ExternalWindow is visible.
  608.       */
  609.     public void setResizable(boolean flag) {
  610.         resizable = flag;
  611.         if( awtWindow != null ) {
  612.             throw new InconsistencyException(
  613.                     "Cannot call setResizable on a visible external window");
  614.         }
  615.     }
  616.  
  617.     /** Returns <b>true</b> if the user can resize the ExternalWindow.
  618.       * @see #setResizable
  619.       */
  620.     public boolean isResizable() {
  621.         return resizable;
  622.     }
  623.  
  624.     /** Returns the FoundationPanel the ExternalWindow uses to display its
  625.       * RootView.
  626.       */
  627.     public FoundationPanel panel() {
  628.         return panel;
  629.     }
  630.  
  631.     /** Sets whether the window contains a document. Windows containing document
  632.       * are treated in a different manner by the target chain.
  633.       *
  634.       */
  635.     public void setContainsDocument(boolean containsDocument) {
  636.         this.containsDocument = containsDocument;
  637.         if(containsDocument == false && Application.application().currentDocumentWindow() == this)
  638.             Application.application().chooseNextCurrentDocumentWindow(this);
  639.         else if(containsDocument == true && Application.application().firstRootView() == rootView())
  640.             Application.application().makeCurrentDocumentWindow(this);
  641.     }
  642.  
  643.     /** Return whether the window contains a document.
  644.       *
  645.       */
  646.     public boolean containsDocument() {
  647.         return containsDocument;
  648.     }
  649.  
  650.     /** If the window contains a document, this method is called
  651.       * when the window just became the current document.
  652.       *
  653.       */
  654.     public void didBecomeCurrentDocument() {
  655.     }
  656.  
  657.     /** If the window contains a document, this method is called
  658.       * when the window is no longer the current document.
  659.       *
  660.       */
  661.     public void didResignCurrentDocument() {
  662.     }
  663.  
  664.     /** Return whether this window is the current document
  665.       *
  666.       */
  667.     public boolean isCurrentDocument() {
  668.         if(Application.application().currentDocumentWindow() == this)
  669.             return true;
  670.         else
  671.             return false;
  672.     }
  673.  
  674.     /* ALERT!
  675.     ** Describes the ExternalWindow class' information.
  676.       * @see Codable#describeClassInfo
  677.       *
  678.     public void describeClassInfo(ClassInfo info) {
  679.         info.addClass("netscape.application.ExternalWindow", 1);
  680.         info.addField(AWTWINDOW_KEY, OBJECT_TYPE);
  681.         info.addField(PANEL_KEY, OBJECT_TYPE);
  682.         info.addField(OWNER_KEY, OBJECT_TYPE);
  683.  
  684.         info.addField(TYPE_KEY, INT_TYPE);
  685.  
  686.         info.addField(MINSIZE_KEY, OBJECT_TYPE);
  687.         info.addField(MENU_KEY, OBJECT_TYPE);
  688.         info.addField(HIDEONPAUSE_KEY, BOOLEAN_TYPE);
  689.         info.addField(CONTAINS_DOCUMENT_KEY,BOOLEAN_TYPE);
  690.     }
  691.  
  692.     ** Encodes the ExternalWindow instance.
  693.       * @see Codable#encode
  694.       *
  695.     public void encode(Encoder encoder) throws CodingException {
  696.         encoder.encodeObject(AWTWINDOW_KEY, awtWindow);
  697.         encoder.encodeObject(PANEL_KEY, panel);
  698.         encoder.encodeObject(OWNER_KEY, owner);
  699.  
  700.         encoder.encodeInt(TYPE_KEY, type);
  701.  
  702.         encoder.encodeObject(MINSIZE_KEY, minimumSize);
  703.         encoder.encodeObject(MENU_KEY, menu);
  704.         encoder.encodeBoolean(HIDEONPAUSE_KEY, hideOnPause);
  705.         encoder.encodeBoolean(CONTAINS_DOCUMENT_KEY, containsDocument);
  706.     }
  707.  
  708.     ** Decodes the ExternalWindow instance.
  709.       * @see Codable#decode
  710.       *
  711.     public void decode(Decoder decoder) throws CodingException {
  712.         awtWindow = (java.awt.Window)decoder.decodeObject(AWTWINDOW_KEY);
  713.         panel = (FoundationPanel)decoder.decodeObject(PANEL_KEY);
  714.         owner = (WindowOwner)decoder.decodeObject(OWNER_KEY);
  715.  
  716.         type = (int)decoder.decodeInt(TYPE_KEY);
  717.  
  718.         minimumSize = (Size)decoder.decodeObject(MINSIZE_KEY);
  719.         menu = (Menu)decoder.decodeObject(MENU_KEY);
  720.         hideOnPause = decoder.decodeBoolean(HIDEONPAUSE_KEY);
  721.     }
  722.  
  723.     ** Finishes the ExternalWindow decoding.
  724.       * @see Codable#finishDecoding
  725.       *
  726.     public void finishDecoding() throws CodingException {
  727.         Application.application().addObserver(this);
  728.     }
  729.     */
  730.  
  731.     /** Creates and returns the ExternalWindow's FoundationDialog.
  732.       * This method will be called if the ExternalWindow has a title bar
  733.       * and is being displayed modally.
  734.       * ExternalWindow subclasses can override this method to provide a
  735.       * custom FoundationDialog subclass.
  736.       * @see FoundationFrame
  737.       */
  738.     protected FoundationDialog createDialog() {
  739.         return new FoundationDialog(firstRootViewParentFrame(), true);
  740.     }
  741.  
  742.     /** Creates and returns the ExternalWindow's FoundationFrame.
  743.       * This method will be called if the ExternalWindow has a title bar.
  744.       * ExternalWindow subclasses can override this method to provide a
  745.       * custom FoundationFrame subclass.
  746.       * @see FoundationFrame
  747.       */
  748.     protected FoundationFrame createFrame() {
  749.         return new FoundationFrame();
  750.     }
  751.  
  752.     /** Creates and returns the ExternalWindow's AWT Window.
  753.       * This method will be called if the ExternalWindow has no title bar.
  754.       * ExternalWindow subclasses can override this method to provide a
  755.       * custom FoundationWindow subclass.
  756.       * @see FoundationWindow
  757.       * @private
  758.       */
  759.     protected FoundationWindow createWindow() {
  760.         return new FoundationWindow(appletParentFrame());
  761.     }
  762.  
  763.     /** Creates and returns the ExternalWindow's FoundationPanel.
  764.       * ExternalWindow subclasses can override this method to provide a
  765.       * custom FoundationPanel subclass.
  766.       * @see FoundationPanel
  767.       */
  768.     protected FoundationPanel createPanel() {
  769.         return new FoundationPanel();
  770.     }
  771.  
  772.     /** ApplicationObserver method. */
  773.     public void applicationDidStart(Application application) {
  774.     }
  775.  
  776.     /** ApplicationObserver method. */
  777.     public void applicationDidStop(Application application) {
  778.         dispose();
  779.     }
  780.  
  781.     /** ApplicationObserver method.
  782.       *
  783.       */
  784.     public void focusDidChange(Application application, View focusedView) {
  785.     }
  786.  
  787.     /** ApplicationObserver method.
  788.       *
  789.       */
  790.     public void currentDocumentDidChange(Application application,
  791.                                          Window document) {
  792.     }
  793.  
  794.     /** ApplicationObserver method.  If <b>hidesWhenPaused()</b> is <b>true</b>
  795.       * and the ExternalWindow is visible, hides the ExternalWindow.
  796.       * @see #setHidesWhenPaused
  797.       * @see #applicationDidResume
  798.       */
  799.     public void applicationDidPause(Application application) {
  800.         if (hideOnPause && visible) {
  801.             hide();
  802.             showOnResume = true;
  803.         }
  804.     }
  805.  
  806.     /** ApplicationObserver method.  If <b>hidesWhenPaused()</b> is <b>true</b>
  807.       * and the ExternalWindow was visible when the Application paused,
  808.       * makes the ExternalWindow visible.
  809.       * @see #setHidesWhenPaused
  810.       * @see #applicationDidPause
  811.       */
  812.     public void applicationDidResume(Application application) {
  813.         if (showOnResume) {
  814.             show();
  815.         }
  816.     }
  817.  
  818.     /** Sets whether the ExternalWindow hides when the Application pauses.
  819.       * If <b>flag</b> is <b>true</b>, the ExternalWindow's
  820.       * <b>applicationDidPause()</b> method hides the Window if the Window
  821.       * is visible.  The <b>applicationDidResume()</b> brings the Window
  822.       * back onscreen.
  823.       * @see #applicationDidPause
  824.       * @see #applicationDidResume
  825.       */
  826.     public void setHidesWhenPaused(boolean flag) {
  827.         hideOnPause = flag;
  828.     }
  829.  
  830.     /** Returns <b>true</b> if the ExternalWindow hides when the Application
  831.       * pauses.
  832.       * @see #setHidesWhenPaused
  833.       */
  834.     public boolean hidesWhenPaused() {
  835.         return hideOnPause;
  836.     }
  837.  
  838.     /** Implements the ExternalWindow's commands:
  839.       * <ul>
  840.       * <li>SHOW - calls the ExternalWindow's <b>show()</b> method, causing
  841.       * the ExternalWindow to appear onscreen.
  842.       * <li>HIDE - calls the ExternalWindow's <b>hide()</b> method,
  843.       * removing the ExternalWindow from the screen.
  844.       * </ul>
  845.       * @see #show
  846.       * @see #hide
  847.       */
  848.     public void performCommand(String command, Object data) {
  849.         if (SHOW.equals(command)) {
  850.             show();
  851.         } else if (HIDE.equals(command)) {
  852.             hide();
  853.         } else {
  854.             throw new NoSuchMethodError("unknown command: " + command);
  855.         }
  856.     }
  857.  
  858.     /** Move the window to the front.
  859.       *
  860.       */
  861.  
  862.     public void moveToFront() {
  863.         if(!isVisible())
  864.             return;
  865.         else {
  866.             awtWindow.toFront();
  867.         }
  868.     }
  869.  
  870.     /** Move the window to the back.
  871.       *
  872.       */
  873.     public void moveToBack() {
  874.         if(!isVisible())
  875.             return;
  876.         else {
  877.             awtWindow.toBack();
  878.         }
  879.  
  880.     }
  881. }
  882.  
  883.